﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VipCo.Data;
using VipCo.Entities;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string tp = Request.Params["SsThanhPho"];
            if (tp != null)
            {
                ThanhPho entTp = DataRepository.ThanhPhoProvider.GetById(Convert.ToInt32(tp));
                if (Session["TP"] != null)
                {
                    // Lay ten Thanh pho                    
                    Session["TP"] = entTp.TenThanhPho; // Ten Thanh Pho
                    Session.Add("IdTp", tp); // Id Thanh Pho
                }
                else
                {
                    Session.Add("TP", entTp.TenThanhPho);
                    Session.Add("IdTp", tp); // Id Thanh Pho
                }
            }
            else
            {
                if (Session["TP"] == null)
                {
                    int totalRows = 0;
                    const string whereClause = "TenThanhPho like N'" + Common.TP_Danang + "' and TrangThai = 1";
                    var tlistThanhPhos = DataRepository.ThanhPhoProvider.GetPaged(whereClause, "Id DESC", 0, 0, out totalRows);

                    Session.Add("IdTp", tlistThanhPhos[0].Id); // Id Thanh Pho
                    Session.Add("TP", Common.TP_Danang);
                }
            }
        }
    }
}